package cn.yunhe.test;

import cn.yunhe.dao.NewsMapper;
import cn.yunhe.entity.News;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

public class test {

    SqlSession sqlSession=null;
    NewsMapper newsMapper=null;

    @Before
    public void init(){
        sqlSession= SqlSessionFactoryUtil.getSqlSesssion();
        newsMapper=sqlSession.getMapper(NewsMapper.class);
    }

    @Test
    public void test1(){
        List<News> newsList=newsMapper.getAllNews();
        for(News n:newsList){
            System.out.println(n.getNewsId()+","+n.getTitle()+","+n.getContext()+","+n.getWriteDate());
        }
    }

    @Test
    public void test2(){
        News n=newsMapper.getNewsById(2);
        System.out.println(n.getNewsId()+","+n.getTitle()+","+n.getContext()+","+n.getWriteDate());

    }


    @Test
    public void test3(){
        News n=sqlSession.selectOne("getNewsById",3);
        System.out.println(n.getNewsId()+","+n.getTitle()+","+n.getContext()+","+n.getWriteDate());
    }

    @After
    public void decoty(){
        sqlSession.close();
    }

}
